import dataConfig from './dataConfig';
import _ from 'lodash';

// 添加
export const addData = function (key: string, options: any) {
	const obj = JSON.parse(options.body).params.obj;
	obj.id = _.uniqueId();
	dataConfig[key].push(obj);
	return dataConfig[key]
}

// 删除
export const deleteData = function (key: string, options: any) {
	const id = JSON.parse(options.body).params.id;
	dataConfig[key] = dataConfig[key].filter((item: any) => item.id != id);
	return dataConfig[key];
}

// 修改
export const updateData = function (key: string, options: any) {
	const obj = JSON.parse(options.body).params.obj;
	const i = dataConfig[key].findIndex((item: any) => item.id === obj.id);
	if (i > -1) dataConfig[key].splice(i, 1, obj);
	return dataConfig[key]
}

// 查询
export const queryData = (key: string, options: any) => {

	const params = JSON.parse(options.body).params;
	console.log(`output->option`, params)
	return dataConfig[key];
}